package com.ygxsk.carhome.ui.adapter;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.tencent.mmkv.MMKV;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.response.ConsignmentVo;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.StringCodeUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-27  15:21
 * @Description:车辆寄售管理主页列表适配器
 */
public class ConsignRecordHistoryAdapter extends BaseQuickAdapter<ConsignmentVo, BaseViewHolder> {

    //填充一个代理进去,因为涉及到权限申请 放在activity之中用；
    private BGANinePhotoLayout.Delegate bgaNinePhotoLayoutDelegate;

    public void setBgaNinePhotoLayoutDelegate(BGANinePhotoLayout.Delegate _bgaNinePhotoLayoutDelegate) {
        bgaNinePhotoLayoutDelegate = _bgaNinePhotoLayoutDelegate;
    }

    public ConsignRecordHistoryAdapter(int layoutResId, @Nullable List<ConsignmentVo> data) {
        super(layoutResId, data);
        addChildClickViewIds(R.id.textviewphoneconsignhistory);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, ConsignmentVo consignmentVo) {

        if (consignmentVo != null) {

            String name = consignmentVo.getCustomerName();
            String phone = consignmentVo.getCustomerPhone();
            String stateItem = consignmentVo.getStatusName();

            //车辆型号是 3段拼接：
            String carBrandName = consignmentVo.getCarBrandName();
            //车系的id
            String carSeriesName = consignmentVo.getCarSeriesName();
            //车辆的品牌
            String vehicleName = consignmentVo.getVehicleName();

            String carModelResult = carBrandName + StringUtils.getString(R.string.kongge0) + carSeriesName + StringUtils.getString(R.string.kongge0) + vehicleName;


            BigDecimal hopePrice = consignmentVo.getGuidePrice();
            String hopePriceResult = "";
            if (hopePrice != null) {
                hopePriceResult = hopePrice.toString();
            } else {
                hopePriceResult = CommUtils.formatComma2BigDecimal(0.00).toString();
            }

            ArrayList<String> images = (ArrayList<String>) consignmentVo.getImgs();
            //认证人员的 姓名
            TextView textViewPersonNameConsignMain = (TextView) baseViewHolder.getView(R.id.textviewpersonnameconsignhistory);
            //寄售人员的 手机号
            TextView textViewPhoneConsignMain = (TextView) baseViewHolder.getView(R.id.textviewphoneconsignhistory);
            //添加人员的状态
            RoundTextView textViewConsignManState = (RoundTextView) baseViewHolder.getView(R.id.textviewconsignhistorystate);
            //车辆型号
            TextView textViewCarModelConsignMain = (TextView) baseViewHolder.getView(R.id.textviewcarmodelconsignhistory);
            //期望价格
            TextView textViewHopePrice = (TextView) baseViewHolder.getView(R.id.textviewhopepricehistory);

            //九宫格附件的外侧包裹：
            LinearLayout linearLayoutImagesHistory = (LinearLayout) baseViewHolder.getView(R.id.linearlayoutimageshistory);

            //图片的九宫格信息
            BGANinePhotoLayout nplItemMomentPhotosConsign = (BGANinePhotoLayout) baseViewHolder.getView(R.id.npl_item_moment_photos_consign_history);

            //填充适配器
            CommUtils.setText(textViewPersonNameConsignMain, name);
//            CommUtils.setText(textViewPhoneConsignMain, phone);
            CommUtils.setText(textViewPhoneConsignMain, StringCodeUtils.mobileEncrypt(phone));

            CommUtils.setText(textViewConsignManState, stateItem);
            CommUtils.setText(textViewCarModelConsignMain, carModelResult);

            //携带货币符号
            CommUtils.setText(textViewHopePrice, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + hopePriceResult + StringUtils.getString(R.string.unitmoney));

            if (images != null && !images.isEmpty()) {
                linearLayoutImagesHistory.setVisibility(View.VISIBLE);
            } else {
                linearLayoutImagesHistory.setVisibility(View.GONE);
            }

            if (nplItemMomentPhotosConsign != null) {

                nplItemMomentPhotosConsign.setData(images);
                nplItemMomentPhotosConsign.setDelegate(bgaNinePhotoLayoutDelegate);

//                nplItemMomentPhotosConsign.setDelegate(new BGANinePhotoLayout.Delegate() {
//                    @Override
//                    public void onClickNinePhotoItem(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
//
//                    }
//
//                    @Override
//                    public void onClickExpand(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
//
//                    }
//                });

            }
        }
    }
}
